<?php

    //TODO finish pages block
    //TODO add admin rights
    //TODO add user login
    //TODO add login types
    //TODO help
    class AdminLogin extends iJBlock
    {
        /**
         *
         * This function is construct Languages
         *
         *
         * @access public
         */
        public function __construct() {
        }
        
        /**
         * execute
         *
         * Executes the block to generate the tokens
         *
         * @return array Array with the tokens of the block
         *
         * @access public
         */
        public function execute() {
          $iJAdmin  = iJFactory::singleton('iJAdmin');
          
          if(isset($_REQUEST['logout'])) {
            $iJSession = iJFactory::singleton('iJSession');
            $iJSession->destroy();
            iJRedirect(iJHrefLink::linkToLocalPage(REDIRECT_AFTER_LOG_OUT));
          }
          
          if(iJAdmin::isAdminLogin()) {
            iJRedirect(iJHrefLink::linkToLocalPage(ADMIN_START_PAGE));
          } 
          
          if(!empty($_POST['password']) && !empty($_POST['username'])) {
              if($iJAdmin->loginRequest($_POST['username'], $_POST['password'])) {
                iJRedirect(iJHrefLink::linkToLocalPage(ADMIN_START_PAGE));
              }        
          }
          $this->addToken('mainPage', iJHrefLink::linkToLocalPage('index'));
          return parent::execute();
        }
        
    }
?>